<?php 
	//链接数据库
	$link=mysqli_connect('localhost','root','');
	//设置链接字符集
	mysqli_set_charset($link,'utf8');
	//选择数据库
	mysqli_select_db($link,'studynote');
	//准备sql语句
	$sql="select * from note order by createtime desc";
	//执行sql语句
	$res=mysqli_query($link,$sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>学习笔记</title>
	<style type="text/css">
		*{margin: 0;padding: 0;}
		body{text-align: center}
		.box{border: 1px solid gray;width: 80%;margin: 10px auto;}
		.box p{clear: both;text-align: left;text-indent: 2em;}
		.box a{text-decoration: none;float: right;}
		hr{border: 1px dashed gray;clear: both;}
		.title_time{width: 100%;height: 25px;}
		.title_time .title{float: left;margin-left: 10px;color: blue;}
		.title_time .time{float: right;margin-right: 10px;}

		.form{border: 1px solid #eeeeee;width: 80%;margin: 5px auto;text-align: left;font-size: 16px;clear: both;}
		.form .input_title{border: 1px solid #c8cccf;font-size:1.4em;height:1.4em;width:80%;margin-left: 10px;}
		.form textarea{border:1px solid gray;padding: 5px 3px 3px 5px;height: 100px;width:80%;margin-left:10px;overflow: scroll;font-size: 1.4em}
		.form p{margin:5px;}
		.form p label{font-size: 20px;}
		input[type='submit']{border: 0;height:50px;width:60px;vertical-align: middle;margin-left: 10px;margin-top:10px;margin-bottom:10px;line-height: 18px;font-size: 18px;cursor:pointer;}
	</style>
</head>
<body>
	<h1>学习笔记</h1>
	<?php
		if($res){
		 while($rows=mysqli_fetch_assoc($res)){
			
	?>
		<div class="box">
			<div class="title_time">
				<span class="title"><?php echo $rows['title'];?></span>
				<span class="time">发表时间:<?php echo date('Y-m-d H:i:s',$rows['createtime']);?></span>
			</div>
			<hr>
			<p>
				<?php echo $rows['content'];?>
				<a href="edit.php?id=<?php echo $rows['id']?>">修改</a>
			</p>
		</div>
	<?php
			}
		}
	?>
	<div class="form">
		<form action="add.php" method="post">
			<p>
				<label>标题:</label> 
				<input type="text" name="title" class="input_title">
			</p>
			<p>
				<label>内容:</label> <textarea name="content"></textarea>
			</p>
			<input type="submit" value="发表">
		</form>
	</div>
	
</body>
</html>